/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd
 ******************************************************************************
 *  @File Name        : kf8a100fxx_stk.h
 *  @Author           : ChipON AE/FAE Group
 *  @Date             : 2023-12-19
 *  @HW Version       : KF8A100Fxx
 *  @Lib Version      : V2.0.1
 *  @Description      : This file provides isr stk protection program
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd
 *  All rights reserved.
 *
 *  This software is copyright protected and proprietary to
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.
 *****************************************************************************/
/******************************************************************************
 *  |Date        |Version  |Author       |Description
 ******************************************************************************
 *  |2024-01-24  |V2.0     |Wang Junxiong|New creat
 *****************************************************************************/

#ifndef KF8A100FXX_STK_H
#define KF8A100FXX_STK_H

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
 *                      Include Files
 *****************************************************************************/
#include "kf8a100fxx.h"
/******************************************************************************
 *                      Document Description
 *****************************************************************************/

/**
 * @brief Notes on the use of interrupt service functions:
 * 1. When you call a function in an interrupt, it is not recommended to call a function with parameters, otherwise
 * parameter protection is required;
 * 2. parameter protection takes up additional RAM addresses and interrupt code, so the timeliness of interrupt response
 * is affected;
 * 3. Protecting the stack code can be called in the right place, thus realizing to make the interrupt execution that
 * does not need the stack to enter and exit quickly;
 * 4. does not support interrupts and external functions calling a function at the same time unless logically marked to
 * never run at the same time (non-stacked process variables fix uniform RAM addresses), restrictions include operations
 * such as multiplication and division, taking a remainder, etc.
 */

/**
 * @brief Notes on the use of functions in this document:
 * 1. Establish a global variable in the file where the interrupt is located, which is used to save the parameters of
 * the function call;
 * 2. Use STK00 ~ STK11 as the parameter transfer, according to the number of specific use can be adjusted to the size
 * of the array elements;
 * 3. Need to confirm the array with the actual protection of the number of parameters consistent. To avoid overflow of
 * the array under the adjustment of the code process.
 */

/******************************************************************************
 *                      Macro or Inline
 *****************************************************************************/

/**
 * @brief If the maximum use is prompted as STK6, the number of 0~6 definitions should be 7.
 *
 */
#define H_STKSAVECOUNT 12
#define L_STKSAVECOUNT 12

/**
 * @brief Defining the STK_PROTECTION_STATE switch protection function via macro
 *
 */
#define STK_PROTECTION_ENABLE  1u
#define STK_PROTECTION_DISABLE 0u
#define STK_PROTECTION_STATE   (STK_PROTECTION_ENABLE)
/*****************************************************************************
 *                      Typedef Definitions
 *****************************************************************************/

/******************************************************************************
 *                      Export Variables
 *****************************************************************************/

/**
 * @brief STK buffer
 *
 */
extern volatile uint8_t H_STKBUFFED[H_STKSAVECOUNT];
extern volatile uint8_t L_STKBUFFED[L_STKSAVECOUNT];
/******************************************************************************
 *                      Export Functions
 *****************************************************************************/

/**
 * @brief Interrupts use stack protection before calling with parameters
 *
 */
void H_ISR_PUSH_STK(void);

/**
 * @brief End of Interrupt Processing Calls Stack Processing
 *
 */
void H_ISR_POP_STK(void);

/**
 * @brief Interrupts use stack protection before calling with parameters
 *
 */
void L_ISR_PUSH_STK(void);

/**
 * @brief End of Interrupt Processing Calls Stack Processing
 *
 */
void L_ISR_POP_STK(void);
#ifdef __cplusplus
}
#endif

#endif
/* EOF */
